package controller;


import java.util.List;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import po.ClassRoom;
import service.ClassService;
@Controller
public class classController {
	// 依赖注入
	@Autowired
	private ClassService classService;	
	@RequestMapping(value = "/class/getClass.action")
	public String list( Model model) {
		List<ClassRoom> classlist = classService.getClassList();
		model.addAttribute("classlist", classlist);	
		return "class_list";

	}
	@RequestMapping("/class/delClass.action")
	public String classDelete(Integer classid) {
		int rows = classService.deleteClass(classid);
		if(rows > 0) {
			System.out.println("OK");
		}else {
			System.out.println("FAIL");
		}
		//System.out.println(userid);
		return "redirect:/class/getClass.action";
	}
	@RequestMapping("/class/addClass.action")
	public String classAdd(ClassRoom classRoom) {
		int rows = classService.addClass(classRoom);
		if(rows > 0) {
			System.out.println("OK");
		}else {
			System.out.println("FAIL");
		}
		return "redirect:/class/getClass.action";
	}
	
	@RequestMapping(value ="/class/getclassId.action")
	@ResponseBody
	public ClassRoom getCLassId(Integer id) {
		ClassRoom data = classService.getCLassId(id);
		return data;
   }  
	
	@RequestMapping(value ="/class/updateClass.action")
	@ResponseBody
	public String updateClass(ClassRoom classRoom) {
		int row = classService.updateClass(classRoom);
		System.out.println(row);
		if(row>0) {
			return "OK";
		}else {
			return "false";
		}
   }
	@RequestMapping(value = "/class/findAll.action")
	public String listAll(String data,Model model) {
		List<ClassRoom> classlist = classService.findList(data);
		model.addAttribute("classlist", classlist);	
		return "class_list";
	}
}
